﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace p166
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string connstring = "Data Source=SWH;Initial Catalog=db_2012;Integrated Security=True";
            SqlConnection connection = new SqlConnection(connstring);
            connection.Open();
            string sqlstring = "select * from Student";
            SqlCommand mycom = new SqlCommand(sqlstring, connection);
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = mycom;
            DataSet SQLds = new DataSet();
            adapter.Fill(SQLds);
            string MSG = "";
            for (int i = 0; i < SQLds.Tables[0].Rows.Count; i++)
            {
                for (int j = 0; j < SQLds.Tables[0].Columns.Count; j++)
                {
                    MSG += SQLds.Tables[0].Rows[i][j].ToString() + " ";
                }
                MSG += "\n";
            }
            MessageBox.Show(MSG);
            connection.Dispose();
            connection.Close();
            connection = null;
        }
    }
}
